﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-22-21:34
//  * @Description:
//  */

using Code.Controller.Component.TimeTask;
using Code.DataManager;
using Code.GameLogic.BaseClass;
using Code.Utility;
using QFramework;
using UnityEngine;

namespace Code.GameLogic.Monster.Controller
{
    public class MonsterFlashPointController:AbsGameLogicController<MonsterFlashPointBo,MonsterManager>
    {
        private int _flashTaskId;

        public override void InitGo(MonsterFlashPointBo bo)
        {
            var spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
            spriteRenderer.sprite = Resources.Load<Sprite>("怪物/刷新点/刷新点");
            spriteRenderer.sortingOrder = 1;
            // 可选：为图像设置位置、旋转和缩放
            gameObject.transform.rotation = Quaternion.identity; // 设置旋转
            var transform1 = transform;
            transform1.localPosition = new Vector3(0, 0, 0);
            transform1.localScale = new Vector3(1, 1, 1); // 设置缩放
            StartFlashTask();
        }

        public void StartFlashTask()
        {
            _flashTaskId = TimeSysManager.Instance.AddTimerTask(bo.FlashSpeed, FlashMonster, TimeType.Second, -1);
        }
        public void StopFlashTask()
        {
            TimeSysManager.Instance.DelTimerTask(_flashTaskId);
        }
        
        
        public void FlashMonster()
        {
            var randomIntForMaxInt = this.GetUtility<RandomUtils>().GetRandomIntForMaxInt(bo.MonsterPoll.Count);
            var monsterType = bo.MonsterPoll[randomIntForMaxInt];
            manager.CreateMonster(monsterType,this);
        }
        
        
    }
}